using System;
using System.Xml;
using System.Text;
using System.Reflection;
using System.ServiceModel;
using System.Collections.Generic;
using System.Runtime.Serialization;
using TDS = Tridion.ContentManager.Interop.TDS;
using TDSDefines = Tridion.ContentManager.Interop.TDSDefines;


#pragma warning disable 649
namespace Tridion.Gateway
{
    /* <?xml version="1.0" ?> 
        <tcm:ListItems xmlns:tcm="http://www.tridion.com/ContentManager/5.0" ID="tcm:0-2-1" Managed="512">
        <tcm:Item ID="tcm:2-2-2" Type="2" Title="Building Blocks" Lock="0" Modified="2008-09-30T23:09:22" Size="0" IsPublished="false" IsShared="false" IsLocalized="false" Trustee="tcm:0-13-65552" IsNew="false" Icon="T2L0P0" /> 
        <tcm:Item ID="tcm:2-3-4" Type="4" Title="Root" Lock="0" Modified="2008-09-30T23:09:38" Size="0" IsPublished="false" IsShared="false" IsLocalized="false" Trustee="tcm:0-13-65552" IsNew="false" Icon="T4L0P0" /> 
        </tcm:ListItems>*
     */

	[DataContract]
	public class Item
	{
		internal Item()
		{
		}

        [DataMember(Name = "ID")]
        private String id;
        public String ID
        {
            get { return id; }
        }


        [DataMember(Name = "ItemType")]
        private TDSDefines.ItemType itemtype;
        public TDSDefines.ItemType ItemType
        {
            get { return itemtype; }
        }


        [DataMember(Name = "Title")]
        private String title;
        public String Title
        {
            get { return title; }
            set { title = value; }
        }

        
        [DataMember(Name = "Lock")]
        private Int32 @lock;
        public Int32 Lock
        {
            get { return @lock; }
        }


		[DataMember(Name="Modified")]
        private DateTime modified;
        public DateTime Modified
		{
            get { return modified; }
		}


        [DataMember(Name = "Size")]
        private Int32 size;
        public Int32 Size
        {
            get { return size; }
        }

        
        [DataMember(Name = "IsPublished")]
        private bool ispublished;
        public bool IsPublished
        {
            get { return ispublished; }
        }


        [DataMember(Name = "IsShared")]
        private bool isshared;
        public bool IsShared
        {
            get { return isshared; }
        }


        [DataMember(Name = "IsLocalized")]
        private bool islocalized;
        public bool IsLocalized
        {
            get { return islocalized; }
        }


        [DataMember(Name="Trustee")]
        private String trustee;
        public String Trustee
        {
            get { return trustee; }
            set { trustee = value; }
        }


        [DataMember(Name = "IsNew")]
        private bool isnew;
        public bool IsNew
        {
            get { return isnew; }
        }


        [DataMember(Name = "Icon")]
        private String icon;
        public String Icon
        {
            get { return icon; }
            set { icon = value; }
        }


        public static Item[] Parse(String ItemList)
        {
            List<Item> itemList = new List<Item>();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(ItemList);
            XmlNamespaceManager nm = new XmlNamespaceManager(doc.NameTable);
            nm.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
            XmlNodeList nodes = doc.SelectNodes("//tcm:Item", nm);
            foreach (XmlNode node in nodes)
            {
                Item item = new Item();
                item.id = node.Attributes["ID"].Value;
                item.itemtype = (TDSDefines.ItemType)Enum.Parse(typeof(TDSDefines.ItemType),node.Attributes["Type"].Value);
                item.title  =  node.Attributes["Title"].Value;
                item.@lock = Int32.Parse(node.Attributes["Lock"].Value);
                item.modified = DateTime.Parse(node.Attributes["Modified"].Value);
                item.size = Int32.Parse(node.Attributes["Size"] == null?"0":node.Attributes["Size"].Value);
                item.ispublished = bool.Parse(node.Attributes["IsPublished"].Value);
                item.islocalized = bool.Parse(node.Attributes["IsLocalized"].Value);
                item.isshared = bool.Parse(node.Attributes["IsShared"].Value);
                item.trustee = node.Attributes["Trustee"].Value;
                item.isnew = bool.Parse(node.Attributes["IsNew"].Value);
                item.icon = node.Attributes["Icon"].Value;
                    
                itemList.Add(item);
            }
            return itemList.ToArray();
        
        }
	}
}

/*
*/
